from django.db import models
from django.db.models.manager import Manager
from django.db.models import CharField, ForeignKey, SmallIntegerField, OneToOneField, TextField, IntegerField


# Create your models here.


class Post(models.Model):
    class Meta:
        db_table = 'post'

    user = ForeignKey('user.user', on_delete=models.DO_NOTHING)
    title = CharField(null=False, max_length=30)
    postdate = CharField(null=False, max_length=13)
    todo_date = CharField(null=False, max_length=13)
    will_complete_date = CharField(null=False, max_length=13)
    priority = SmallIntegerField(null=False, default=0)
    hard = SmallIntegerField(null=False, default=0)
    todo_count = IntegerField(null=False, default=0)
    is_completed = SmallIntegerField(null=False, default=0)
    is_deleted = SmallIntegerField(null=False, default=0)
    is_hidden = SmallIntegerField(null=False, default=0)

    def __repr__(self):
        return "< Post {} {} {} {} >".format(
            self.title, self.postdate, self.todo_count, self.is_completed
        )

    __str__ = __repr__


class Content(models.Model):
    class Meta:
        db_table = 'content'

    post = OneToOneField('post', on_delete=models.DO_NOTHING)
    content = TextField(null=False)
    pic = CharField(null=True, max_length=20)
    video = CharField(null=True, max_length=20)

    def __repr__(self):
        return "< Content {} {} {} >".format(self.post, self.content, self.pic)

    __str__ = __repr__


post_manger: Manager = getattr(Post, 'objects')
cont_manger: Manager = getattr(Content, 'objects')
